package com.gly091020.mixin;

import com.gly091020.EnglishFight;
import com.gly091020.client.EnglishFightClient;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PlayerInventory.class)
public class SelectAnswerMixin {
    @Shadow @Final public PlayerEntity player;

    @Inject(method = "scrollInHotbar", at = @At("HEAD"), cancellable = true)
    public void setAnswer(double scrollAmount, CallbackInfo ci){
        if (EnchantmentHelper.getLevel(EnglishFight.ENGLISH_FIGHT, player.getMainHandStack()) > 0){
            EnglishFightClient.switchAnswer(scrollAmount);
            ci.cancel();
        }
    }
}
